package com.seecen.cywbackend.controller;

import com.seecen.cywbackend.pojo.User;
import com.seecen.cywbackend.pojo.vo.LoginUser;
import com.seecen.cywbackend.service.UserService;
import com.seecen.cywbackend.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserService userService;

    // 手机号/用户名、密码登录
    @PostMapping("/pwdLogin")
    public Result pwdLogin(@RequestBody LoginUser loginUser){
        return userService.pwdLogin(loginUser);
    }

    //手机号登录（未注册手机号自动注册）
    @GetMapping("/codeLogin")
    public Result codeLogin(@RequestParam String phone){
        return  userService.codeLogin(phone);
    }

    // 获取用户信息
    @GetMapping("/getUserInfo")
    public Result getUserInfo(@RequestHeader String token) {
        String pureToken = token.replace("Bearer ", "");
        return userService.getUserInfo(pureToken);
    }

    @GetMapping("/sendCode")
    public Result sendCode(@RequestParam String phone){
        return userService.sendCode(phone);
    }

}
